<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .contain{
      width: 200px;
      height: 200px;
      background-color: aqua;
      margin: 100px auto;
      /* 方式一 弹性盒子
      /* display: flex;
      justify-content: center;
      align-items: center; */
      position: relative;
    }
    .item{
      /* 方式二  开启绝对定位 将top left right bottom设为0 必须要设置子元素的宽高才能达到效果
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      width: 50px;
      height: 50px;
      margin: auto;
      */
      /* 方式三  将top设为50% bottom设为50% transform向左合上平移元素的宽高一半的距离*/
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background-color: antiquewhite;
    }

  </style>
</head>
<body>
  <div class="contain">
    <div class="item">块状物体</div></div>
  </div>
</body>
</html>